import cv2
import numpy as np

# 读取图像
img_path = r"D:\DATA\20250519RENBAO\temp\000100+pose_official+cls_img100_200_cls7_augmean3_pad+v3.jpg"
image = cv2.imread(img_path)

# 手动选择四个点（例如通过鼠标点击）
# 这里假设你已经知道这四个点的位置
x1, y1 = 0, 441
x2, y2 = 0, 792
x3, y3 = 1912, 920
x4, y4 = 1917, 295

width, height = image.shape[1], image.shape[0]
new_x1, new_y1 = 0, 0
new_x2, new_y2 = 0, 1080
new_x3, new_y3 = 1920, 1080
new_x4, new_y4 = 1920, 0
src_points = np.float32([[x1, y1], [x2, y2], [x3, y3], [x4, y4]])

# 定义这四个点在新图像中的位置
dst_points = np.float32([[new_x1, new_y1], [new_x2, new_y2], [new_x3, new_y3], [new_x4, new_y4]])

# 计算透视变换矩阵
M = cv2.getPerspectiveTransform(src_points, dst_points)

# 应用透视变换
corrected_image = cv2.warpPerspective(image, M, (width, height))

# 显示结果
cv2.imwrite(f'{img_path[:-4]}_res.jpg', corrected_image)